package com.linux.huhx.redis;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @Author: huhx
 * @Date: 2017-11-23 下午 5:48
 */
public class RedisTest {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 6379);
        socket.setReuseAddress(true);
        String data = "get username\n";
        socket.getOutputStream().write(data.getBytes());

        InputStream inputStream = socket.getInputStream();
        int length = inputStream.available();
        byte[] buffer = new byte[length];
        inputStream.read(buffer);

        // 对buffer做处理
        String string = new String(buffer, "utf-8");
        System.out.println(string);
        socket.close();
    }
}